package com.myweb.common;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * 功能描述: 分页处理类
 * @作者 : roye zl007_ml@126.com
 * @创建日期 : Apr 16, 20134:39:44 PM
 * */
public class Page {

		private static Set<String> canFormatType; 
		private Integer count;
		private Integer start;
		private Integer limit;
		private String sort;
		private String dir;
		private String callback;
		private List<?> queryResult;
		
		public Integer getCount() {
			return count;
		}

		public void setCount(Integer count) {
			this.count = count;
		}

		public Integer getStart() {
			return start;
		}

		public void setStart(Integer start) {
			if(start == null || start.intValue()<0){
				start = 0;
			}
			this.start = start;
		}

		public Integer getLimit() {
			return limit;
		}

		public void setLimit(Integer limit) {
			if(limit == null || limit.intValue() <0 ){
				limit = 10;
			}
			this.limit = limit;
		}

		public String getSort() {
			if(sort == null || "".equals(sort)){
				return "id";
			}
			return sort;
		}

		public void setSort(String sort) {
			this.sort = sort;
		}

		public String getDir() {
			return dir;
		}

		public void setDir(String dir) {
			if(dir == null){
				dir = "asc";
			}
			this.dir = dir;
		}

		public String getCallback() {
			return callback;
		}

		public void setCallback(String callback) {
			this.callback = callback;
		}
		
		public Order getOrder(){
			if(sort==null || "".equals(sort.trim())){
				if("asc".equals(dir.toLowerCase())){
					return Order.asc("id");
				}else{
					return Order.desc("id");
				}
			}else{
				if("asc".equals(dir.toLowerCase())){
					return Order.asc(sort);
				}else{
					return Order.desc(sort);
				}
			}
		}
		
		public String getOrderString() {
			if(sort==null || "".equals(sort.trim())){
				if("asc".equals(dir.toLowerCase())){
					return " order by id";
				}else{
					return " order by id desc";
				}
			}else{
				if("asc".equals(dir.toLowerCase())){
					return  " order by "+sort;
				}else{
					return " order by "+sort +" desc";
				}
			}
		}
		
		public List<?> getQueryResult() {
			return queryResult;
		}

		public void setQueryResult(List<?> queryResult) {
			this.queryResult = queryResult;
		}

		
}
